using UnityEngine;

public class LevelUpLayer : MonoBehaviour
{
	public struct LevelProgressInfo
	{
		public float levelProgress;

		public string levelName;
	}

	public LevelUpDisplayControl levelUpDisplay;

	public static LevelUpLayer instance { get; protected set; }

	private void Awake()
	{
		instance = this;
		BehaviourSingletonInit<GGServerMessages>.instance.onMessageExecuted += OnGGMessageExecuted;
	}

	private void OnGGMessageExecuted()
	{
		GGPlayerSettings gGPlayerSettings = GGPlayerSettings.instance;
		LevelProgressInfo levelProgressInfo = default(LevelProgressInfo);
		levelProgressInfo.levelProgress = gGPlayerSettings.LevelProgress();
		levelProgressInfo.levelName = gGPlayerSettings.LevelName();
		LevelProgressInfo oldLevel = levelProgressInfo;
		levelProgressInfo = default(LevelProgressInfo);
		levelProgressInfo.levelProgress = gGPlayerSettings.LevelProgress();
		levelProgressInfo.levelName = gGPlayerSettings.LevelName();
		LevelProgressInfo newLevel = levelProgressInfo;
		instance.DoShowLevelProgress(oldLevel, newLevel);
	}

	private void OnDestroy()
	{
		BehaviourSingletonInit<GGServerMessages>.instance.onMessageExecuted -= OnGGMessageExecuted;
		instance = null;
	}

	public void DoShowLevelProgress(LevelProgressInfo oldLevel, LevelProgressInfo newLevel)
	{
		LevelUpDisplayControl.GameParams gameParams = new LevelUpDisplayControl.GameParams();
		gameParams.SetLevels(oldLevel.levelProgress, newLevel.levelProgress);
		gameParams.SetLevelNames(oldLevel.levelName, newLevel.levelName);
		gameParams.SetDelegate(null);
		levelUpDisplay.ShowAnim(gameParams);
	}
}
